using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CS490_Capstone___Stubby.Page
{
    public partial class Search : System.Web.UI.Page
    {
        // create webservice object
        WebServiceApplication.WebService webservice = new WebServiceApplication.WebService();

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                _OpenEvent OE = webservice.getSearchedEvent(searchTerm.Text);
                if (OE.eventName == null)
                // do nothing other than highlight which fields are incomplete or invalid
                {
                    Session["SearchEventValue"] = null;
                }
                else
                // beginning of the valid input block -- do what the button is supposed to do
                {
                    // Create a session variable for the recreateVenueTable method.
                    try
                    {
                        Session["SearchEventValue"] = OE.eventName;
                    }
                    catch (NullReferenceException)
                    {
                        Session.Remove("SearchEventValue");
                        Session.Add("SearchEventValue", OE.eventName);
                    }
                }

                if (Session["SearchEventValue"].ToString() != null)
                {
                    recreateVenueTable();
                }

                try
                {
                    if (Session["searchVenueName"].ToString() != null)
                    {
                        try
                        {
                            string venueName = Session["searchVenueName"].ToString();
                            Table table = new Table();
                            foreach (_Ticket ticket in webservice.getTicketsFromVenue(Session["SearchEventValue"].ToString(), venueName))
                            {
                                TableRow row = new TableRow();

                                TableCell checkboxCell = new TableCell();
                                checkboxCell.HorizontalAlign = HorizontalAlign.Center;
                                CheckBox checkbox = new CheckBox();
                                checkbox.ID = "eventName" + ticket.eventName + " venueName" + ticket.venueName + " sectionName" + ticket.sectionName + " row" + ticket.row + " seat" + ticket.seat + " price" + ticket.price;
                                checkboxCell.Width = Convert.ToInt32((checkbox.Width.Value * 8));
                                checkboxCell.Controls.Add(checkbox);

                                TableCell ticketTypeCell = new TableCell();
                                ticketTypeCell.HorizontalAlign = HorizontalAlign.Left;
                                Label ticketType = new Label();
                                ticketType.Text = ticket.className.ticketType;
                                ticketTypeCell.Width = Convert.ToInt32((ticketType.Text.Length * 8));
                                ticketTypeCell.Controls.Add(ticketType);

                                TableCell sectionCell = new TableCell();
                                sectionCell.HorizontalAlign = HorizontalAlign.Left;
                                Label section = new Label();
                                section.Text = ticket.sectionName;
                                sectionCell.Width = Convert.ToInt32((section.Text.Length * 8));
                                sectionCell.Controls.Add(section);

                                TableCell rowCell = new TableCell();
                                rowCell.HorizontalAlign = HorizontalAlign.Left;
                                Label rowContent = new Label();
                                rowContent.Text = ticket.row;
                                rowCell.Width = Convert.ToInt32((rowContent.Text.Length * 8));
                                rowCell.Controls.Add(rowContent);

                                TableCell seatCell = new TableCell();
                                seatCell.HorizontalAlign = HorizontalAlign.Left;
                                Label seat = new Label();
                                seat.Text = ticket.seat;
                                seatCell.Width = Convert.ToInt32((seat.Text.Length * 8));
                                seatCell.Controls.Add(seat);

                                TableCell priceCell = new TableCell();
                                priceCell.HorizontalAlign = HorizontalAlign.Left;
                                Label price = new Label();
                                price.Text = ticket.seat;
                                priceCell.Width = Convert.ToInt32((price.Text.Length * 8));
                                priceCell.Controls.Add(price);

                                row.Controls.Add(checkboxCell);
                                row.Controls.Add(ticketTypeCell);
                                row.Controls.Add(sectionCell);
                                row.Controls.Add(rowCell);
                                row.Controls.Add(seatCell);
                                row.Controls.Add(priceCell);

                                table.Controls.Add(row);
                            }
                            table.HorizontalAlign = HorizontalAlign.Center;
                            searchResultsPanel.Controls.Add(table);

                            btn_ProceedToCheckout.Visible = true;
                        }
                        catch (NullReferenceException)
                        // if the search does not return results a NullReferenceException will occur
                        // in that case, or if for any other reason the results are wonky, tell user to try again
                        {
                            searchResults.InnerHtml += "<tr>";
                            searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
                            searchResults.InnerHtml += "</tr>";
                            searchResults.InnerHtml += "<tr>";
                            searchResults.InnerHtml += "<td class='noResults' colspan='5'>No results for &quot;" +
                                searchTerm.Text + "&quot; were found. Please try again.</td>";
                            searchResults.InnerHtml += "</tr>";
                            searchResults.InnerHtml += "<tr>";
                            searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
                            searchResults.InnerHtml += "</tr>";
                        }
                    }
                }
                catch (NullReferenceException)
                {
                    // Do nothing, the object hasn't been activated.
                }
            }
            catch (NullReferenceException)
            {
                // Skip creating the table. There is not a searched item to populate the table with.
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            String browserHeight;
            int contentHeight;

            // read screen height passed through URL
            if (Request.QueryString.ToString() != "")
            {
                HtmlGenericControl searchBody = (HtmlGenericControl)Page.Master.FindControl("myBody");
                // displays the appropriate header menu
                searchBody.Attributes.Add("onload", "showJavaScriptHeader();");

                // sets browser height to the visible browser height as passed by the query string
                // sets browser height to minimum of 550px if browser height is smaller
                browserHeight = (int.Parse(Request.QueryString["height"].ToString()) > 550) 
                    ? Request.QueryString["height"].ToString() : "550";
            }
            else
            // this block fires if JavaScript is not enabled or if the page is called without a height 
            // attribute, as at start up
            {
                HtmlGenericControl searchBody = (HtmlGenericControl)Page.Master.FindControl("myBody");
                // if JavaScript is enabled the page is reloaded with the browser height
                searchBody.Attributes.Add("onload", "getBrowserHeight();");

                // sets browser height to default 800px if browser height cannot be determined
                browserHeight = "800";
            }

            // calculate and set the size of the input panel to fill the screen
            content.Height = contentHeight = int.Parse(browserHeight) - 120;
            topSpacer.Height = ((contentHeight - 70) / 2) - 15 > 0 ? ((contentHeight - 70) / 2) - 15 : 0; 
        }

        private bool validInput()
        {
            // char array to test input against
            char[] badChar = "*&#()[]{}%$@<>?/\\~`=!^|\":;".ToCharArray();

            // change background color of all fields white
            searchTerm.BackColor = System.Drawing.Color.White;

            // checks to see if searchTerm is invalid/incomplete
            if (searchTerm.Text == "" || searchTerm.Text == "Event or Artist Name" || 
                searchTerm.Text == "Search Again" || searchTerm.Text == "Try Again" ||
                searchTerm.Text.IndexOfAny(badChar) >= 0)
            {
                searchTerm.Text = "Try Again";
                searchTerm.BackColor = System.Drawing.ColorTranslator.FromHtml("#FEF201"); ;
            }

            if (searchTerm.BackColor.Equals(System.Drawing.ColorTranslator.FromHtml("#FEF201")))
            // invalid/incomplete input detected
            {
                return false;
            }
            // no invalid/incomplete input detected
            else
            {
                return true;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!validInput())
            // do nothing other than highlight which fields are incomplete or invalid
            {
                // search box text changes to "search again".
                searchTerm.Text = "Search Again";
            }
            else
            // beginning of the valid input block -- do what the button is supposed to do
            {
                // when the button is clicked the search and spacer labels should disappear 
                //and the output panel appear
                searchLabel.Visible = false;
                labelSpacer.Visible = false;
                output.Visible = true;
                
                // get search results from database
                recreateVenueTable();

            } // close of the valid input block
        }

        private void recreateVenueTable()
        {
            int eventNameWidth = 0;
            int eventDateWidth = 0;
            int cityStateWidth = 0;
            int venueWidth = 0;
            int priceWidth = 0;

            try
            {
                // get event using searchTerm
                _OpenEvent ev = webservice.getSearchedEvent(Session["SearchEventValue"].ToString());

                // get a list of venues for that event
                List<_Venue> myList = webservice.getVenuesFromEvent(ev.eventName);
                Table dynamicTable = new Table();

                try
                // if results are available, create table rows
                {
                    // row index, used for determining LinkButton ID
                    int i = 0;

                    foreach (_Venue row in myList)
                    // steps through each venue in the list
                    {
                        TableRow tableRow = new TableRow();

                        // variables for computing price range
                        double min = 10000000;
                        double max = 0;


                        // get a list of tickets to determine prices
                        List<_Ticket> ticketList = webservice.getTicketsFromVenue(ev.eventName,
                            row.venueName);

                        // step through each ticket and assign value to the minimum and maximum base price
                        // max and min only have a particular value for a single iteration of the row loop
                        // max and min will be calculated in each iteration, as each pricing could differ
                        if (ticketList.Count == 0)
                        {
                            min = 0;
                            max = 0;
                        }
                        foreach (_Ticket t in ticketList)
                        {
                            if (t.ticketAvailable == false)
                                break;

                            if ((double)t.basePrice > max)
                            {
                                // set maximum base price
                                max = (double)t.basePrice;
                            }
                            if ((double)t.basePrice < min)
                            {
                                // set minimum base price
                                min = (double)t.basePrice;
                            }
                        }

                        // open row and populate data cells

                        // event name
                        TableCell eventNameCell = new TableCell();
                        eventNameCell.Width = (ev.eventName.Length * 8);
                        if (eventNameCell.Width.Value > eventNameWidth)
                            eventNameWidth = Convert.ToInt32(eventNameCell.Width.Value);
                        eventNameCell.HorizontalAlign = HorizontalAlign.Left;
                        LinkButton mynewlink = new LinkButton();
                        mynewlink.ID = "Link" + row.venueName + i++;
                        mynewlink.Click += new EventHandler(recreateTickets);
                        mynewlink.Text = ev.eventName;
                        eventNameCell.Controls.Add(mynewlink);

                        // event date
                        TableCell eventDateCell = new TableCell();
                        eventDateCell.HorizontalAlign = HorizontalAlign.Left;
                        Label eventDate = new Label();
                        string eventDateText = row.dateStart.ToShortDateString();
                        eventDateCell.Width = (eventDateText.Length * 8);
                        if (eventDateCell.Width.Value > eventDateWidth)
                            eventDateWidth = Convert.ToInt32(eventDateCell.Width.Value);
                        eventDate.Text = eventDateText;
                        eventDateCell.Controls.Add(eventDate);

                        // event city, state
                        TableCell eventCityStateCell = new TableCell();
                        eventCityStateCell.HorizontalAlign = HorizontalAlign.Left;
                        Label eventCityState = new Label();
                        string eventCityStateText = row.city + ", " + row.state;
                        eventCityState.Text = eventCityStateText;
                        eventCityStateCell.Width = (eventCityStateText.Length * 8);
                        if (eventCityStateCell.Width.Value > cityStateWidth)
                            cityStateWidth = Convert.ToInt32(eventCityStateCell.Width.Value);
                        eventCityStateCell.Controls.Add(eventCityState);

                        // event venue
                        TableCell venueCell = new TableCell();
                        venueCell.HorizontalAlign = HorizontalAlign.Left;
                        Label venuelbl = new Label();
                        string venueText = row.venueName;
                        venuelbl.Text = venueText;
                        venueCell.Width = (venueText.Length * 8);
                        if (venueCell.Width.Value > venueWidth)
                            venueWidth = Convert.ToInt32(venueCell.Width.Value);
                        venueCell.Controls.Add(venuelbl);

                        TableCell priceCell = new TableCell();
                        priceCell.HorizontalAlign = HorizontalAlign.Left;
                        Label pricelbl = new Label();
                        string priceText = "$" + String.Format("{0:0.00}", min) + " - " + String.Format("{0:0.00}", max);
                        pricelbl.Text = priceText;
                        priceCell.Width = (priceText.Length * 8);
                        if (priceCell.Width.Value > priceWidth)
                            priceWidth = Convert.ToInt32(priceCell.Width.Value);
                        priceCell.Controls.Add(pricelbl);

                        tableRow.Controls.Add(eventNameCell);
                        tableRow.Controls.Add(eventDateCell);
                        tableRow.Controls.Add(eventCityStateCell);
                        tableRow.Controls.Add(venueCell);
                        tableRow.Controls.Add(priceCell);
                        tableRow.HorizontalAlign = HorizontalAlign.Left;

                        dynamicTable.Controls.Add(tableRow);

                        dynamicTable.Width = Convert.ToInt32(output.Width.Value);
                    }
                }
                catch
                // if the search does not return results a NullReferenceException will occur
                // in that case, or if for any other reason the results are wonky, tell user to try again
                {
                    searchResults.InnerHtml += "<tr>";
                    searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
                    searchResults.InnerHtml += "</tr>";
                    searchResults.InnerHtml += "<tr>";
                    searchResults.InnerHtml += "<td class='noResults' colspan='5'>No results for &quot;" +
                        searchTerm.Text + "&quot; were found. Please try again.</td>";
                    searchResults.InnerHtml += "</tr>";
                    searchResults.InnerHtml += "<tr>";
                    searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
                    searchResults.InnerHtml += "</tr>";
                }

                dynamicTable.HorizontalAlign = HorizontalAlign.Center;

                searchResultsPanel.Controls.Clear();

                // create search results table header row
                searchResults.InnerHtml = "<h3>Results for " + searchTerm.Text + ":</h3>";
                searchResults.InnerHtml += "<table id='outputTable' runat='server' class='results'>";
                searchResults.InnerHtml += "<tr>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + eventNameWidth + "'>Event Name</td>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + eventDateWidth + "'>Date</td>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + cityStateWidth + "'>City, State</td>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + venueWidth + "'>Venue</td>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + priceWidth + "'>Price Range</td>";
                searchResults.InnerHtml += "</tr>";

                if (ev.eventName != null)
                {
                    searchResultsPanel.Controls.Add(dynamicTable);
                }

                topSpacer.Height = 20;
            }
            catch (NullReferenceException)
            {
                // if the search does not return results a NullReferenceException will occur
                // in that case, or if for any other reason the results are wonky, tell user to try again
                searchResults.InnerHtml += "<tr>";
                searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
                searchResults.InnerHtml += "</tr>";
                searchResults.InnerHtml += "<tr>";
                searchResults.InnerHtml += "<td class='noResults' colspan='5'>No results for &quot;" +
                    searchTerm.Text + "&quot; were found. Please try again.</td>";
                searchResults.InnerHtml += "</tr>";
                searchResults.InnerHtml += "<tr>";
                searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
                searchResults.InnerHtml += "</tr>";

                // There is nothing populated in the dataset. Return empty table.

                // create search results table header row
                searchResults.InnerHtml = "<h3>Results for " + searchTerm.Text + ":</h3>";
                searchResults.InnerHtml += "<table id='outputTable' runat='server' class='results'>";
                searchResults.InnerHtml += "<tr>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + eventNameWidth + "'>Event Name</td>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + eventDateWidth + "'>Date</td>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + cityStateWidth + "'>City, State</td>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + venueWidth + "'>Venue</td>";
                searchResults.InnerHtml += "<td class='column' align='center' width='" + priceWidth + "'>Price Range</td>";
                searchResults.InnerHtml += "</tr>";
            }
        }

        protected void recreateTickets(object sender, EventArgs e)
        {
            LinkButton temp = (LinkButton)sender;
            string venueName = "";
            if (temp.ID.StartsWith("Link"))
            {
                char[] trimChar = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'};
                venueName = temp.ID.Remove(0, 4);
                venueName = venueName.TrimEnd(trimChar);
                try
                {
                    Session["searchVenueName"] = venueName;
                }
                catch (NullReferenceException)
                {
                    Session.Remove("searchVenueName");
                    Session.Add("searchVenueName", venueName);
                }
            }

            int ticketTypeWidth = 0;
            int sectionWidth = 0;
            int rowWidth = 0;
            int seatWidth = 0;
            int priceWidth = 0;

            try
            {
                Table table = new Table();
                foreach (_Ticket ticket in webservice.getTicketsFromVenue(Session["SearchEventValue"].ToString(), venueName))
                {
                    TableRow row = new TableRow();

                    TableCell checkboxCell = new TableCell();
                    checkboxCell.HorizontalAlign = HorizontalAlign.Center;
                    CheckBox checkbox = new CheckBox();
                    checkbox.ID = "eventName" + ticket.eventName + " venueName" + ticket.venueName + " sectionName" + ticket.sectionName + " row" + ticket.row + " seat" + ticket.seat + " price" + ticket.price;
                    checkboxCell.Width = Convert.ToInt32((checkbox.Width.Value * 8));
                    checkboxCell.Controls.Add(checkbox);

                    TableCell ticketTypeCell = new TableCell();
                    ticketTypeCell.HorizontalAlign = HorizontalAlign.Left;
                    Label ticketType = new Label();
                    ticketType.Text = ticket.className.ticketType;
                    ticketTypeCell.Width = Convert.ToInt32((ticketType.Text.Length * 8));
                    ticketTypeCell.Controls.Add(ticketType);

                    TableCell sectionCell = new TableCell();
                    sectionCell.HorizontalAlign = HorizontalAlign.Left;
                    Label section = new Label();
                    section.Text = ticket.sectionName;
                    sectionCell.Width = Convert.ToInt32((section.Text.Length * 8));
                    sectionCell.Controls.Add(section);

                    TableCell rowCell = new TableCell();
                    rowCell.HorizontalAlign = HorizontalAlign.Left;
                    Label rowContent = new Label();
                    rowContent.Text = ticket.row;
                    rowCell.Width = Convert.ToInt32((rowContent.Text.Length * 8));
                    rowCell.Controls.Add(rowContent);

                    TableCell seatCell = new TableCell();
                    seatCell.HorizontalAlign = HorizontalAlign.Left;
                    Label seat = new Label();
                    seat.Text = ticket.seat;
                    seatCell.Width = Convert.ToInt32((seat.Text.Length * 8));
                    seatCell.Controls.Add(seat);

                    TableCell priceCell = new TableCell();
                    priceCell.HorizontalAlign = HorizontalAlign.Left;
                    Label price = new Label();
                    price.Text = ticket.seat;
                    priceCell.Width = Convert.ToInt32((price.Text.Length * 8));
                    priceCell.Controls.Add(price);

                    row.Controls.Add(checkboxCell);
                    row.Controls.Add(ticketTypeCell);
                    row.Controls.Add(sectionCell);
                    row.Controls.Add(rowCell);
                    row.Controls.Add(seatCell);
                    row.Controls.Add(priceCell);

                    table.Controls.Add(row);
                }
                table.HorizontalAlign = HorizontalAlign.Center;
                searchResultsPanel.Controls.Add(table);

                btn_ProceedToCheckout.Visible = true;
            }
            catch (NullReferenceException)
            // if the search does not return results a NullReferenceException will occur
            // in that case, or if for any other reason the results are wonky, tell user to try again
            {
                searchResults.InnerHtml += "<tr>";
                searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
                searchResults.InnerHtml += "</tr>";
                searchResults.InnerHtml += "<tr>";
                searchResults.InnerHtml += "<td class='noResults' colspan='5'>No results for &quot;" +
                    searchTerm.Text + "&quot; were found. Please try again.</td>";
                searchResults.InnerHtml += "</tr>";
                searchResults.InnerHtml += "<tr>";
                searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
                searchResults.InnerHtml += "</tr>";
            }


            //    searchResultsPanel.Controls.Clear();

            //    // create search results table header row
            //    searchResults.InnerHtml = "<h3>Results for " + searchTerm.Text + ":</h3>";
            //    searchResults.InnerHtml += "<table id='outputTable' runat='server' class='results'>";
            //    searchResults.InnerHtml += "<tr>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + eventNameWidth + "'>Event Name</td>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + eventDateWidth + "'>Date</td>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + cityStateWidth + "'>City, State</td>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + venueWidth + "'>Venue</td>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + priceWidth + "'>Price Range</td>";
            //    searchResults.InnerHtml += "</tr>";

            //    if (ev.eventName != null)
            //    {
            //        searchResultsPanel.Controls.Add(dynamicTable);
            //    }

            //    topSpacer.Height = 20;
            //}
            //catch (NullReferenceException)
            //{
            //    // if the search does not return results a NullReferenceException will occur
            //    // in that case, or if for any other reason the results are wonky, tell user to try again
            //    searchResults.InnerHtml += "<tr>";
            //    searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
            //    searchResults.InnerHtml += "</tr>";
            //    searchResults.InnerHtml += "<tr>";
            //    searchResults.InnerHtml += "<td class='noResults' colspan='5'>No results for &quot;" +
            //        searchTerm.Text + "&quot; were found. Please try again.</td>";
            //    searchResults.InnerHtml += "</tr>";
            //    searchResults.InnerHtml += "<tr>";
            //    searchResults.InnerHtml += "<td class='list' colspan='5'>&nbsp;</td>";
            //    searchResults.InnerHtml += "</tr>";

            //    // There is nothing populated in the dataset. Return empty table.

            //    // create search results table header row
            //    searchResults.InnerHtml = "<h3>Results for " + searchTerm.Text + ":</h3>";
            //    searchResults.InnerHtml += "<table id='outputTable' runat='server' class='results'>";
            //    searchResults.InnerHtml += "<tr>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + eventNameWidth + "'>Event Name</td>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + eventDateWidth + "'>Date</td>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + cityStateWidth + "'>City, State</td>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + venueWidth + "'>Venue</td>";
            //    searchResults.InnerHtml += "<td class='column' align='center' width='" + priceWidth + "'>Price Range</td>";
            //    searchResults.InnerHtml += "</tr>";
            //}
        }

        private void ProceedToCheckout()
        {
            List<_Ticket> ticketList = new List<_Ticket>();
            foreach (Control ctrl in searchResultsPanel.Controls)
            {
                if (ctrl is Table)
                {
                    Table table = (Table)ctrl;
                    foreach (TableRow row in table.Rows)
                    {
                        foreach (TableCell cell in row.Cells)
                        {
                            foreach (Control cellCtrl in cell.Controls)
                            {
                                if (cellCtrl is CheckBox)
                                {
                                    CheckBox cb = (CheckBox)cellCtrl;
                                    if (cb.Checked == true)
                                    {
                                        _Ticket ticket = new _Ticket();

                                        string[] words = cb.ID.Split();
                                        string temp = "";
                                        foreach (string word in words)
                                        {
                                            if (word.Contains("eventName"))
                                            {
                                                temp = word;
                                            }
                                            else if (word.Contains("venueName"))
                                            {
                                                ticket.eventName = temp.Remove(0, 9);
                                                temp = word;
                                            }
                                            else if (word.Contains("sectionName"))
                                            {
                                                ticket.venueName = temp.Remove(0, 9);
                                                temp = word;
                                            }
                                            else if (word.Contains("row"))
                                            {
                                                ticket.sectionName = temp.Remove(0, 11);
                                                temp = word;
                                            }
                                            else if (word.Contains("seat"))
                                            {
                                                ticket.row = temp.Remove(0, 3);
                                                temp = word;
                                            }
                                            else if (word.Contains("price"))
                                            {
                                                ticket.seat = temp.Remove(0, 4);
                                                temp = word;
                                            }
                                            else
                                            {
                                                temp += " " + word;
                                            }
                                        }
                                        ticket.price = Convert.ToDecimal(temp.Remove(0, 5));
                                        ticketList.Add(ticket);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            try
            {
                Session["ProceedToCheckout"] = ticketList;
            }
            catch (NullReferenceException)
            {
                Session.Remove("ProceedToCheckout");
                Session.Add("ProceedToCheckout", ticketList);
            }
        }

        protected void btn_ProceedToCheckout_Click(object sender, EventArgs e)
        {
            ProceedToCheckout();
            Response.Redirect("~/Web Pages/Checkout.aspx");
        }
    }
}